'''
基金数据库
基金数据库分为两个表，基金历史信息表和基金实时信息表
'''

from app.dao import dao
from app.utils import log


# import dao
# 继承dao类
class Fund_DAO(dao.DAO):


    _instance = None

    def __new__(cls, *args, **kwargs):
        if not cls._instance:
            cls._instance = super().__new__(cls)

        return cls._instance

    def __init__(self):
        self.logger= log.Logger(__name__)
        super().__init__()

    def get_all(self):
        sql = 'select * from fund_maininfo'
        values = self.execute_query(sql)
        return values
    def get_fund_info(self, fund_code):
        sql = 'select * from ls_symbolquotationd where symbol = \'%s\'' % fund_code
        _values = self.execute_query(sql)
        name=''
        #返回格式如下["2019-3-16", 18.4, 18.58, 18.33, 18.79, 67.0, 1, 0.04, 0.11, 0.09]
        #去掉每一行的第2-4列
        ret = []
        for value in _values:
            value = list(value)
            value.pop(1)
            value.pop(1)
            #向前补齐6位

            name=value.pop(1)
            value.pop()
            #calculate DEA 并追加
            #add a column
            #calculate DIF
            #calculate MACD
            value.append(0)
            value.append(0)
            value.append(0)
            value.append(0)
            value.append(0)



            ret.append(value)
        return {'data':ret,'name':name}
        # return [["2019-3-16", 18.4, 18.58, 18.33, 18.79, 67.0, 1, 0.04, 0.11, 0.09]]


    def get_info(self, fund_code):
        sql = 'select * from fund_maininfo where fund_code = \'%s\'' % (fund_code)
        values = self.execute_query(sql)
        return values

    def get_daily_report(self, fund_code):
        sql = 'select * from fund_daily_report where fund_code = \'%s\'' % (fund_code)
        values = self.execute_query(sql)
        return values

if __name__=="__main__":
    fund_dao = Fund_DAO()
    values = fund_dao.get_all()
    print(values)
    values = fund_dao.get_fund_info('000001')
    print(values)
    values = fund_dao.get_one('000001')
    print(values)